package org.jetlinks.community.mstn.web;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.Resource;
//import org.hswebframework.web.crud.query.QueryHelper;
import org.hswebframework.web.system.authorization.api.entity.DimensionUserEntity;
import org.hswebframework.web.system.authorization.api.entity.UserEntity;
import org.hswebframework.web.system.authorization.defaults.service.DefaultReactiveUserService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/mstn/user")
@Authorize
@Resource(id = "user", name = "用户管理", group = "mstn")
@Tag(name = "用户管理")
@AllArgsConstructor
public class UserController {

//    private final DefaultReactiveUserService reactiveUserService;

//    private final QueryHelper queryHelper;
//    @GetMapping("/search")
//    @Authorize(merge = false)
//    @Operation(summary = "管理员查询数据")
//    public Mono<PagerResult<UserView>> search(){
//        return queryHelper.select(UserView.class)
//                .all(UserView.class, UserView::setOrgList)
//                .all(UserEntity.class)
//                .from(UserEntity.class)
//                .leftJoin(DimensionUserEntity.class,
//                    join -> join.is(DimensionUserEntity::getDimensionId, UserEntity::getId))
//
//                .fetchPaged();
//
//    }

    @GetMapping("/permission/list")
    @Authorize(merge = false)
    @Operation(summary = "获取权限列表")
    public Mono<Void> permissionList(){
        return Authentication.currentReactive().flatMap(authentication -> {

            for (Permission permission : authentication.getPermissions()){
                System.out.println(permission.getName());
            }
            return Mono.empty();
        });
    }
}
